const gulp = require('gulp');
const fileinclude  = require('gulp-file-include');
const del = require('del');
const { series } = require('gulp');
const connect = require('gulp-connect');

// 清除 dist 文件夹
gulp.task('clean', function () {
    return del([
        './dist/**/*',
    ]);
});

//
gulp.task('pack', async function() {
    gulp.src(['./src/**', '!src/include/**'])
        .pipe(fileinclude({
            prefix: '@@',
            basepath: '@file',
            indent:true//保留文件的缩进
        }))
        .pipe(gulp.dest('./dist'))
        .pipe(connect.reload());
});

// // 连接服务器热更新
// gulp.task('server', function() {
//     connect.server({
//         root: 'dist',
//         livereload: true,
//         port: 8030
//     });
// });
//
// gulp.task("reload", async function(){
//     gulp.src("./dist/*.html")
//         .pipe(connect.reload());
// });



// 监测文件变化 watch
gulp.task('watch', function () {
    gulp.watch('./src/**', series('pack'),  function (cb) {

    });
});


gulp.task("default", series('pack', 'watch'));

// 打包构建
gulp.task('build', series('clean', 'pack'));


